/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                                                                  *
 *        *************************************************         *
 *        *©2021-2027 HT Corporation All rights reserved *          *
 *        *************************************************         *
 *                                                                  *
 * FileName    : h_sys.c                                            *
 *                                                                  *
 * Author      : linus                                              *
 *                                                                  *
 * Email       : luoyaojun@haitutech.com                            *
 *                                                                  *
 * Date        : 2022-8-9                                           *
 *                                                                  *
 * Description :                                                    *
 *                                                                  *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include "h_sys.h"
#include "ht_sys.h"

// HT_S32 ht_mpp_init(void)
//{
//	//	在不支持constructor的情况下，在此逐个注册平台相关模块
//	config_xml_init();
//	return 0;
// }

HT_S32 ht_sys_module_register(struct ht_sys *psys)
{
    return (ht_register_modules(HT_ID_SYS, (HT_HANDLE)psys));
}

HT_S32 ht_sys_init(void)
{
    struct ht_sys *psys = HT_MPP_HANDLE_SYS;
    HT_S32 ret = -1;

    //	ret = ht_mpp_init();

    //	if (ret)
    //		return -1;

    if (psys->ops)
    {
        if (psys->ops->ht_sys_init)
            ret = psys->ops->ht_sys_init();
    }

    return ret;
}

HT_S32 ht_sys_exit(void)
{
    struct ht_sys *psys = HT_MPP_HANDLE_SYS;
    HT_S32 ret = -1;

    if (psys->ops)
    {
        if (psys->ops->ht_sys_exit)
            ret = psys->ops->ht_sys_exit();
    }

    return ret;
}

/*
**
**	dst为vo时，dev为layer的值
**	dst为venc时，dst_chn为venc chn
**
*/
HT_S32 ht_sys_bind(HT_MOD_ID src_mid, HT_U32 src_dev, HT_U32 src_chn, HT_MOD_ID dst_mid, HT_U32 dst_dev, HT_U32 dst_chn)
{
    struct ht_sys *psys = HT_MPP_HANDLE_SYS;
    HT_S32 ret = -1;

    if (src_mid < 0 || src_mid >= HT_ID_BUTT || dst_mid < 0 || dst_mid >= HT_ID_BUTT)
        return -2;

    if (psys->ops)
    {
        if (psys->ops->ht_sys_bind)
            ret = psys->ops->ht_sys_bind(src_mid, src_dev, src_chn, dst_mid, dst_dev, dst_chn);
    }

    printf("HT_SYS_BIND: %d-%d-%d -> %d-%d-%d, ret = %08x\n", src_mid, src_dev, src_chn, dst_mid, dst_dev, dst_chn,
           ret);

    return ret;
}

HT_S32 ht_sys_unbind(HT_MOD_ID src_mid, HT_U32 src_dev, HT_U32 src_chn, HT_MOD_ID dst_mid, HT_U32 dst_dev,
                     HT_U32 dst_chn)
{
    struct ht_sys *psys = HT_MPP_HANDLE_SYS;
    HT_S32 ret = -1;

    if (src_mid < 0 || src_mid >= HT_ID_BUTT || dst_mid < 0 || dst_mid >= HT_ID_BUTT)
        return -2;

    if (psys->ops)
    {
        if (psys->ops->ht_sys_unbind)
            ret = psys->ops->ht_sys_unbind(src_mid, src_dev, src_chn, dst_mid, dst_dev, dst_chn);
    }

    return ret;
}


